﻿using SAD_Assignment1.DAO;
using SAD_Assignment1.DTO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Helpers;

namespace SAD_Assignment1.BLO
{
    public class PhotoBLO
    {
        public List<PhotoDTO> getNewPhotoList(int page, int maxPhoto)
        {
            PhotoDAO photoDAO = new PhotoDAO();
            return photoDAO.getPhotoList(page, maxPhoto, 1);
        }

        public List<PhotoDTO> getVotePhotoList(int page, int maxPhoto)
        {
            PhotoDAO photoDAO = new PhotoDAO();
            return photoDAO.getPhotoList(page, maxPhoto, 2);
        }


        public List<PhotoDTO> getPhoto(int photoID)
        {
            PhotoDAO photoDAO = new PhotoDAO();
            return photoDAO.getPhoto(photoID);
        }

        public void ResizePhoto(string filePath)
        {            
            WebImage newImg = new WebImage(filePath);
            int height = newImg.Height;
            int width = newImg.Width;
            if (width > 650)
            {
                height = 650 * height / width;
                width = 650;
            }            
            newImg.Resize(width, height);            
            newImg.Save(filePath);
        }

        public bool AddNewPhoto(string title, string url, string email)
        {
            PhotoDAO photoDAO = new PhotoDAO();
            return photoDAO.AddNewPhoto(title, url, email);
        }

        public bool ApprovePhoto(int photoID)
        {
            PhotoDAO photoDAO = new PhotoDAO();
            return photoDAO.ApprovePhoto(photoID);
        }

        public bool DeletePhoto(int photoID)
        {
            PhotoDAO photoDAO = new PhotoDAO();
            return photoDAO.DeletePhoto(photoID);
        }
    }
}